package com.jy.rhin.infra.repo.notfication.subscribe.query.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.jy.rhin.domain.notification.topic.entity.EnumFilterType;
import com.jy.rhin.sdk.dto.notification.resp.DicDetailDto;
import com.jy.rhin.sdk.dto.notification.resp.SubscribeDetailDto;
import com.jy.rhin.sdk.dto.notification.resp.SubscribeFilterInfoDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * @Description:
 * @Author: lww
 * @Date: 2022/7/1 9:44
 */
@Data
public class SubscribeFullDto {

    public SubscribeDetailDto toDetailDto() {
        SubscribeDetailDto detailDto = new SubscribeDetailDto();
        detailDto.setId(this.id);
        detailDto.setSubscribeUid(this.subscribeUid);
        detailDto.setSubscriberCode(this.subscriberCode);
        detailDto.setSubscriberName(this.subscriberName);
        detailDto.setTopicExp(this.topicExp);
        detailDto.setTopicName(this.topicName);
        detailDto.setQueryExp(this.queryExp);
        detailDto.setQueryName(this.queryName);
        return detailDto;
    }

    public SubscribeFilterInfoDto toFilterInfoDto() {
        if (StringUtils.isEmpty(this.filterExp)) {
            return null;
        }
        SubscribeFilterInfoDto filterInfoDto = new SubscribeFilterInfoDto();
        filterInfoDto.setFilterExp(this.filterExp);
        filterInfoDto.setFilterName(this.filterName);
        filterInfoDto.setFilterType(this.getFilterType());
        filterInfoDto.setFilterCode(this.getFilterCode());
        filterInfoDto.setDicList(Collections.emptyList());
        filterInfoDto.setRangeFlag(EnumFilterType.valueOf(this.filterType) == EnumFilterType.TEXT ? Boolean.FALSE : Boolean.TRUE);
        filterInfoDto.setRangeCode(this.filterCode);
        filterInfoDto.setValue(this.value);
        filterInfoDto.setTargetPath(this.targetPath);
        filterInfoDto.setJsonPath(this.targetPath);

        return filterInfoDto;
    }

    @ApiModelProperty(value = "主键id")
    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long id;
    @ApiModelProperty(value = "订阅标识符")
    private String subscribeUid;
    @ApiModelProperty(value = "订阅者编码")
    private String subscriberCode;
    @ApiModelProperty(value = "订阅者名称")
    private String subscriberName;
    @ApiModelProperty(value = "订阅者交互方式")
    private String interactionType;
    @ApiModelProperty(value = "订阅主题表达式")
    private String topicExp;
    @ApiModelProperty(value = "订阅主题名称")
    private String topicName;
    @ApiModelProperty(value = "预存查询函数表达式")
    private String queryExp;
    @ApiModelProperty(value = "使用的预存查询函数名称")
    private String queryName;
    @ApiModelProperty(value = "过滤条件表达式")
    private String filterExp;
    @ApiModelProperty(value = "过滤条件名称")
    private String filterName;
    @ApiModelProperty(value = "值域标识")
    private Boolean rangeFlag;
    @ApiModelProperty(value = "值域code")
    private String rangeCode;
    @ApiModelProperty(value = "过滤条件取值")
    private String value;
    @ApiModelProperty(value = "取值路径")
    private String targetPath;

    @ApiModelProperty(value = "取值路径")
    private String filterType;
    @ApiModelProperty(value = "取值路径")
    private String filterCode;
    @ApiModelProperty(value = "取值路径")
    private List<DicDetailDto> dicList;
}
